package com.yyk.yiliao.adapter;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

import java.util.List;

/**
 * Created by Administrator on 2018/10/4 0004.
 * <p>
 * 适用于普通的引导页
 */

public class WenjiankangAdapter extends PagerAdapter {
    private List<View> list;
    private Context context;

    public WenjiankangAdapter(List<View> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        // TODO Auto-generated method stub
        int p = position % list.size();
        View img = list.get(p);
        ViewParent parent = img.getParent();
        if (parent != null) {
            ViewGroup vg = (ViewGroup) parent;
            vg.removeView(img);
        }
        container.addView(list.get(p));
        return list.get(p);

    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        // TODO Auto-generated method stub
        int p = position % list.size();
        container.removeView(list.get(p));
    }
}
